package com.ease.platform.access.service.impl;

import java.sql.CallableStatement;
import java.sql.SQLException;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.CallableStatementCallback;

import com.ease.model.DatabaseTable;
import com.ease.platform.access.service.DatabaseWorkspaceAccessService;

/**
 * 
 * @author nathanleewei
 * 
 */
public class DatabaseWorkspaceAccessServiceImpl extends AbstractParameterizedBeanJdbcTemplateAccessServiceImpl<DatabaseTable> implements DatabaseWorkspaceAccessService {

	/* EXECUTE DBMS_WM.GotoWorkspace ('LIVE'); */
	public void gotoWorkspace(final String workspace) {
		String sql = "{call DBMS_WM.GotoWorkspace(?)}";

		this.getJdbcTemplateDataAccessObject().getJdbcTemplate().execute(sql, new CallableStatementCallback<Object>() {
			public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
				cs.setString("workspace", workspace);
				cs.execute();
				return null;
			}
		});

		// StoredProcedureParam storedProcedureParam = new
		// StoredProcedureParam();
		// storedProcedureParam.setCallString("DBMS_WM.GotoWorkspace");
		//
		// List<SqlParameter> declareParameters= new ArrayList<SqlParameter>();
		// storedProcedureParam.setDeclareParameters(declareParameters);
		//
		// SqlParameter sqlParameter = new
		// SqlParameter("workspace",java.sql.Types.VARCHAR);
		// declareParameters.add(sqlParameter);
		//
		// MapParameter mapParameter = new MapParameter();
		// mapParameter.put("workspace", workspace);
		// this.getJdbcTemplateDataAccessObject().execute(storedProcedureParam,
		// mapParameter);
	}

}
